/**
 * 
 */
package nullby.omnia.activity.user;

import nullby.common.utils.CustomLog;
import nullby.omnia.R;
import nullby.omnia.activity.ActivityMain;
import nullby.omnia.db.DatabaseHelper;
import nullby.omnia.model.User;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;

/**
 * 
 * @author Sergey Bandysik </br>[bandysik[at]gmail[dot]com]
 * 
 */
public class ActivityRegistration extends Activity implements OnClickListener {
	private static final String TAG = ActivityRegistration.class
			.getSimpleName();

	private EditText etLogin;
	private EditText etPassword;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		CustomLog.logI(TAG, "onCreate");
		super.onCreate(savedInstanceState);
		initView();
	}

	protected void initView() {
		setContentView(R.layout.activity_registration);

		etLogin = (EditText) findViewById(R.id.etLogin);
		etPassword = (EditText) findViewById(R.id.etPassword);

		findViewById(R.id.bLogIn).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		CustomLog.logI(TAG, "onClick");
		Integer id = v.getId();
		if (id == R.id.bLogIn) {
			autorization();
		}

	}

	private void autorization() {
		User user = DatabaseHelper.get().auth(etLogin.getText().toString(),
				etPassword.getText().toString());
		if (user != null) {
			Toast.makeText(this, "GREAT", 0).show();
			Intent intent = new Intent(this, ActivityMain.class);
			startActivity(intent);
		} else {
			Toast.makeText(this, "BAD", 0).show();
		}
	}
}
